export default {
    data() {
        return {

        }
    },
    computed: {
        basin() {
            return this.$store.getters.basin
        }
    },
    watch: {
        basin: {
            handler: function(name) {
                this.$nextTick(() => {
                    this.creatWATAM(name)
                })
            },
            immediate: true
        }
    },
    created() {
        this._entitiesWATAM = []
    },
    methods: {
        creatWATAM(name) {
            this.clearWATAM()
            if (this.layerList2[1].children.WATAM.show) {
                var url = `${mapConfig.resUrlPre}/geojson/${this.basin}/WATAM.json`
                this.$axios.get(url).then(res => {
                    var lonlats = []
                    var coordinates = res.data.features[0].geometry.coordinates[0]
                    coordinates.forEach(coordinate => {
                        lonlats.push(...coordinate)
                    })
                    var polylineEntity = {
                        polyline: {
                            positions: Cesium.Cartesian3.fromDegreesArray(lonlats),
                            width: 3,
                            // material: new Cesium.PolylineOutlineMaterialProperty({
                            //     color: Cesium.Color.fromCssColorString('rgb(255,219,19)')
                            //     // outlineColor: Cesium.Color.WHITE,
                            //     // outlineWidth: 1
                            // }),
                            material: Cesium.Color.fromCssColorString('rgb(0, 255, 216)'),
                            clampToGround: true,
                            classificationType: Cesium.ClassificationType.TERRAIN // Cesium.ClassificationType.BOTH
                        }
                    }
                    this._entitiesWATAM.push(this.$viewer.entities.add(polylineEntity))
                })
            } else {
                this.clearWATAM()
            }
        },
        clearWATAM() {
            if (this._entitiesWATAM && this._entitiesWATAM.length > 0) {
                this._entitiesWATAM.forEach(item => {
                    this.$viewer.entities.remove(item)
                })
                this._entitiesWATAM = []
            }
        }
    }
}
